import { Select } from 'antd'
import { useDispatch, useSelector } from 'react-redux'

import { useEffect } from 'react'
import { getChannels } from '@/store/actions'

const { Option } = Select

export const Channel = ({ value, onChange, width }) => {
  const dispatch = useDispatch()
  const { channels } = useSelector((state) => state.article)

  useEffect(() => {
    dispatch(getChannels())
  }, [dispatch])

  return (
    <Select
      placeholder="请选择文章频道"
      style={{ width }}
      allowClear
      value={value}
      onChange={onChange}
    >
      {channels.map((item) => (
        <Option key={item.id} value={item.id}>
          {item.name}
        </Option>
      ))}
    </Select>
  )
}
